import React from "react";
import {useDispatch,useSelector} from "react-redux"
import { increment ,decrement } from "../../store/slice/countSlice";
export default function Count() {
  const dispatch = useDispatch()
  const count = useSelector(state => {
    return state.count.count
  })
  const accumulation = () => {
    dispatch(increment(1))
  }
  const accumulateMinus = () => {
    dispatch(decrement(1))
  }
  const ifOddDecrementHandle = () => {
    if(count % 2 !== 0){
    dispatch(increment(1))
    }
  }
  const waitDecrementHandle = () => {
    // dispatch(equalityAction(1))
  }
  return (
    <div>
      <h1>我是Count组件，我的值是{count}</h1>
      <button onClick={accumulation}>累加</button>
      <button onClick={accumulateMinus}>累减</button>
      <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
      <button onClick={waitDecrementHandle}>等2s再加1</button>
    </div>
  );
}
